home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / dev / lang / HeliOS3.lha / helios_demo_disk3 / source / IntuitionGadgets.src < prev    next >
Encoding:
Text File  |  1995-02-24  |  23.1 KB  |  578 lines

  1.  
  2.   (            --------------------------------------------
  3.                ***    HeliOS Intuition Gadget Example   ***
  4.                --------------------------------------------
  5.  
  6.    This demonstration code shows how to set up an absolutely standard
  7.    Amiga intuition based gadget program, including the initialisation of
  8.    Intuition structures etc.
  9.  
  10.    In fact, this code is included only as an exercise in how to initialise
  11.    structures at run-time, which needs to be done in HeliOS if you allocate
  12.    32-bit addressed data structures within the 16-bit dictionary space.
  13.  
  14.    Usually it is better to allocate all Amiga data structures dynamically
  15.    at run time rather than initialise them in the 16-bit dictionary space.
  16.  
  17.    Nevertheless, this code does at least give you an alternative approach
  18.    which is OK for very simple applications.
  19.  
  20.    Actually, HeliOS contains a set of special routines which handle all
  21.    Gadget allocation and useage in a comprehensive way, and these special
  22.    HeliOS gadget routines insulate you from all "housekeeping" tasks such
  23.    as the initialisation of structures.
  24.  
  25.    The special HeliOS gadget routines are very powerful and you will find
  26.    that using them is very easy - far preferable, in fact, to the methods
  27.    used here.  The fact is, though, that they insulate you to such an extent
  28.    from the "hard work" of dealing directly with Intuition that you would
  29.    not be aware of the way Intuition gadget structures really work.
  30.  
  31.    For the above mentioned reason we think you should at least be familiar
  32.    with the "long winded" method used here, before using the "easy way".
  33.  
  34.    Interestingly, to give you a "taste of what is to come", using the
  35.    special HeliOS gadget system all you have to do to set up, say, 25
  36.    gadgets is to allocate the gadgets like this:
  37.  
  38.    25 GADGETS
  39.  
  40.    Then to initialise a particular gadget, you merely say something like
  41.  
  42.    20 20 100 40 (GAD1ACTION) 1 MOVEGADGET
  43.  
  44.    to place gadget "1", sized 100x40, to do (GAD1ACTION), at position 20 20.
  45.  
  46.    Then you say 1 ONGADGET or 1 OFFGADGET.......and one word GADCHECK
  47.    will automatically carry out the gadget action.
  48.  
  49.    The code below is rather more involved, but is nevertheless an example
  50.    of how to use standard Amiga programing techniques.
  51.  
  52.    ---------------------------------------------------------------------
  53.  
  54.    So, to deal with the present code......this HeliOS source code module
  55.    contains:
  56.  
  57.    1. A fully commented predefined Intuition Gadget data structure.
  58.  
  59.    2. Run-time gadget initialisation code for setting up the internal
  60.       32-bit pointers of structures allocated in the 16-bit dictionary.
  61.  
  62.    3. A fully functional gadget command interpreter which can, if required,
  63.       easily be integrated with a Helios menu command interpreter.
  64.  
  65.    4. A simple Demo program which opens a Workbench window and
  66.       carries out gadget commands.
  67.  
  68.    All the material can be readily modified to your own specific
  69.    requirements and provides a simple basis for dealing with other
  70.    similar structure-oriented Amiga OS programming tasks.
  71.  
  72.    To produce your own application all you need to do is alter the
  73.    data structures to suit your particular requirements, then enter
  74.    your own routines into the command vector table in place of the
  75.    Demo commands.
  76.  
  77.    The run-time initialisation routines have been written in such
  78.    a way as to be very easy to understand and modify, but this
  79.    is not ideal in terms of speed and efficiency. Once you are
  80.    confident about what is happening you can easily speed up this
  81.    initialisation code if you wish, and it may be a worthwhile exercise
  82.    to do so.
  83.  
  84.  
  85.  
  86.                       <<<  *** IMPORTANT ***  >>>
  87.  
  88.                      WHY RUN-TIME INITIALISATION ?
  89.  
  90.             WHY NOT INITIALISE THE STRUCTURE AS IT IS DECLARED?
  91.  
  92.  
  93.    You MUST dynamically set up all data structure links and pointers
  94.    at run-time if you wish to be able to save the data structure as
  95.    part of a precompiled HeliOS code module.
  96.  
  97.    This has to be done because your data structures will obviously (?!) not
  98.    be reloaded into the same absolute position in memory as they occupied
  99.    when you first created them. This means that all the absolute pointers
  100.    in the structure must be re-initialised each time the module is loaded. )
  101.  
  102.  \ ----------------------------------------------------------
  103.  \ "FORGET" all but core dictionary.
  104.  \ ----------------------------------------------------------
  105.  
  106.    FORGET **CORE**
  107.  
  108.  \ ----------------------------------------------------------
  109.  \  First we define all the Text Strings we require.
  110.  \  (In this case we are using 6 gadgets, all with text.)
  111.  \  Edit the text strings below to your own requirements.
  112.  \ ----------------------------------------------------------
  113.     CREATEL GADGET1$   <$ Gadget1$
  114.     CREATEL GADGET2$   <$ Gadget2$
  115.     CREATEL GADGET3$   <$ Gadget3$
  116.     CREATEL GADGET4$   <$ Gadget4$
  117.     CREATEL GADGET5$   <$ Gadget5$
  118.     CREATEL GADGET6$   <$ Gadget6$
  119.  \ ----------------------------------------------------------
  120.  \ Now set up Gadget data structure, unlinked at this stage.
  121.  \ Note that we only need remember the address of the first,
  122.  \ and also that we store each gadget's Intuitext structure
  123.  \ immediately after the gadget for ease of initialisation.
  124.  \ -----------------------------------------------------------
  125.  \ Gadget Structure
  126.  \ -----------------------------------------------------------
  127.  \ GADGET1 (Boolean)
  128.  \ -----------------------------------------------------------
  129.                  0. DVARIABLEL GADGLIST      \ Next Gadget
  130.                  40  ,                       \ LEdge
  131.                  60  ,                       \ TEdge
  132.                  80  ,                       \ Width
  133.                  16  ,                       \ Height
  134.                  0   ,                       \ Flags
  135.                  1   ,                       \ Activation
  136.                  1   ,                       \ Type
  137.                 0.  D,                       \ Render    18-offset
  138.                 0.  D,                       \ Select Render
  139.                 0.  D,                       \ Text      26-offset
  140.                 0.  D,                       \ MExclude
  141.                 0.  D,                       \ Special Info
  142.                  1   ,                       \ ID
  143.                 0.  D,                       \ User Data 44-Bytes
  144.  \ ----------------------------------------------------------
  145.                  1  C,                       \ FPEN    Gadget1 Text
  146.                  0  C,                       \ BPEN
  147.                  1  C,                       \ MODE
  148.                  0  C,                       \ KLUDGE
  149.                  11  ,                       \ LEDGE
  150.                  4   ,                       \ TEDGE
  151.                  0. D,                       \ FONT
  152.                  0. D,                       \ TEXT      12-offset
  153.                  0. D,                       \ NEXTTEXT  20-Bytes
  154.  \ -----------------------------------------------------------
  155.  \ GADGET2 (Boolean)
  156.  \ -----------------------------------------------------------
  157.                  0. D,                       \ Next Gadget
  158.                  220 ,                       \ LEdge
  159.                  60  ,                       \ TEdge
  160.                  80  ,                       \ Width
  161.                  16  ,                       \ Height
  162.                  0   ,                       \ Flags
  163.                  1   ,                       \ Activation
  164.                  1   ,                       \ Type
  165.                 0.  D,                       \ Render
  166.                 0.  D,                       \ Select Render
  167.                 0.  D,                       \ Text
  168.                 0.  D,                       \ MExclude
  169.                 0.  D,                       \ Special Info
  170.                  2   ,                       \ ID
  171.                 0.  D,                       \ User Data
  172.  \ ----------------------------------------------------------
  173.                  1  C,                       \ FPEN    Gadget2 Text
  174.                  0  C,                       \ BPEN
  175.                  1  C,                       \ MODE
  176.                  0  C,                       \ KLUDGE
  177.                  11  ,                       \ LEDGE
  178.                  4   ,                       \ TEDGE
  179.                  0. D,                       \ FONT
  180.                  0. D,                       \ TEXT
  181.                  0. D,                       \ NEXTTEXT
  182.  \ -----------------------------------------------------------
  183.  \ GADGET3 (Boolean)
  184.  \ -----------------------------------------------------------
  185.                 0.  D,                       \ Next Gadget
  186.                400   ,                       \ LEdge
  187.                60    ,                       \ TEdge
  188.                 80   ,                       \ Width
  189.                 16   ,                       \ Height
  190.                  0   ,                       \ Flags
  191.                  1   ,                       \ Activation
  192.                  1   ,                       \ Type
  193.                 0.  D,                       \ Render
  194.                 0.  D,                       \ Select Render
  195.                 0.  D,                       \ Text
  196.                 0.  D,                       \ MExclude
  197.                 0.  D,                       \ Special Info
  198.                  3   ,                       \ ID
  199.                 0.  D,                       \ User Data
  200.  \ ----------------------------------------------------------
  201.                  1  C,                       \ FPEN    Gadget3 Text
  202.                  0  C,                       \ BPEN
  203.                  1  C,                       \ MODE
  204.                  0  C,                       \ KLUDGE
  205.                  11  ,                       \ LEDGE
  206.                  4   ,                       \ TEDGE
  207.                  0. D,                       \ FONT
  208.                  0. D,                       \ TEXT
  209.                  0. D,                       \ NEXTTEXT
  210.  \ -----------------------------------------------------------
  211.  \ GADGET4 (Boolean)
  212.  \ -----------------------------------------------------------
  213.                 0.  D,                       \ Next Gadget
  214.                 40   ,                       \ LEdge
  215.                116   ,                       \ TEdge
  216.                 80   ,                       \ Width
  217.                 16   ,                       \ Height
  218.                  0   ,                       \ Flags
  219.                  1   ,                       \ Activation
  220.                  1   ,                       \ Type
  221.                 0.  D,                       \ Render
  222.                 0.  D,                       \ Select Render
  223.                 0.  D,                       \ Text
  224.                 0.  D,                       \ MExclude
  225.                 0.  D,                       \ Special Info
  226.                  4   ,                       \ ID
  227.                 0.  D,                       \ User Data
  228.  \ ----------------------------------------------------------
  229.                  1  C,                       \ FPEN    Gadget4 Text
  230.                  0  C,                       \ BPEN
  231.                  1  C,                       \ MODE
  232.                  0  C,                       \ KLUDGE
  233.                  11  ,                       \ LEDGE
  234.                  4   ,                       \ TEDGE
  235.                  0. D,                       \ FONT
  236.                  0. D,                       \ TEXT
  237.                  0. D,                       \ NEXTTEXT
  238.  \ -----------------------------------------------------------
  239.  \ GADGET5 (Boolean)
  240.  \ -----------------------------------------------------------
  241.                 0.  D,                       \ Next Gadget
  242.                 220  ,                       \ LEdge
  243.                 116  ,                       \ TEdge
  244.                 80   ,                       \ Width
  245.                 16   ,                       \ Height
  246.                  0   ,                       \ Flags
  247.                  1   ,                       \ Activation
  248.                  1   ,                       \ Type
  249.                 0.  D,                       \ Render
  250.                 0.  D,                       \ Select Render
  251.                 0.  D,                       \ Text
  252.                 0.  D,                       \ MExclude
  253.                 0.  D,                       \ Special Info
  254.                  5   ,                       \ ID
  255.                 0.  D,                       \ User Data
  256.  \ ----------------------------------------------------------
  257.                  1  C,                       \ FPEN    Gadget5 Text
  258.                  0  C,                       \ BPEN
  259.                  1  C,                       \ MODE
  260.                  0  C,                       \ KLUDGE
  261.                  11  ,                       \ LEDGE
  262.                  4   ,                       \ TEDGE
  263.                  0. D,                       \ FONT
  264.                  0. D,                       \ TEXT
  265.                  0. D,                       \ NEXTTEXT
  266.  \ -----------------------------------------------------------
  267.  \ GADGET6 (Boolean)
  268.  \ -----------------------------------------------------------
  269.                 0.  D,                       \ Next Gadget
  270.                400   ,                       \ LEdge
  271.                116   ,                       \ TEdge
  272.                 80   ,                       \ Width
  273.                 16   ,                       \ Height
  274.                  0   ,                       \ Flags
  275.                  1   ,                       \ Activation
  276.                  1   ,                       \ Type
  277.                 0.  D,                       \ Render
  278.                 0.  D,                       \ Select Render
  279.                 0.  D,                       \ Text
  280.                 0.  D,                       \ MExclude
  281.                 0.  D,                       \ Special Info
  282.                  6   ,                       \ ID
  283.                 0.  D,                       \ User Data
  284.  \ ----------------------------------------------------------
  285.                  1  C,                       \ FPEN    Gadget6 Text
  286.                  0  C,                       \ BPEN
  287.                  1  C,                       \ MODE
  288.                  0  C,                       \ KLUDGE
  289.                  11  ,                       \ LEDGE
  290.                  4   ,                       \ TEDGE
  291.                  0. D,                       \ FONT
  292.                  0. D,                       \ TEXT
  293.                  0. D,                       \ NEXTTEXT
  294.  \ ----------------------------------------------------------
  295.  \ Etc etc ...... Add as many gadgets as you require.........
  296.  \ ----------------------------------------------------------
  297.  \ Then declare the total number of gadgets as GADGET#
  298.  
  299.  \ In this case there are 6 Gadgets, so ........
  300.  
  301.    6 CONSTANT GADGET#
  302.  
  303.  \ -----------------------------------------------------------
  304.  \ Border Structure
  305.  \ -----------------------------------------------------------
  306.     0 VARIABLEL BORDER1                      \ LEdge
  307.                  0   ,                       \ TEdge
  308.                  3  C,                       \ FPen
  309.                  0  C,                       \ BPen
  310.                  1  C,                       \ DrawMode
  311.                  5  C,                       \ Count
  312.                  0. D,                       \ Coords
  313.                  0. D,                       \ NextBorder
  314.  
  315.     0 VARIABLEL COORD1 0   ,                 \ Coord1
  316.                  79  , 0   ,                 \ Coord2
  317.                  79  , 15  ,                 \ Coord3
  318.                  0   , 15  ,                 \ Coord4
  319.                  0   , 0   ,                 \ Coord5
  320.  
  321.  \ -----------------------------------------------------------
  322.  \ Now create words to reference the various structures
  323.  \ ----------------------------------------------------------
  324.  
  325.    : GADGET         \  Gadget number(w) - - - Structure Address(l)
  326.  
  327.      1- 64 *        \  Offset into list of gadgets
  328.      0              \  Make into 32-bit number
  329.      GADGLIST D+ ;  \  Add to start address
  330.  
  331.  
  332.    : GADTEXT        \  Gadget number(w) - - - Structure Address(l)
  333.  
  334.      GADGET 44. D+ ;
  335.  
  336.  \ ----------------------------------------------------------
  337.  \ And now a word to initialise the gadgets.........
  338.  \ ----------------------------------------------------------
  339.  
  340.    : INITGADGETS
  341.  
  342.      GADGET6$ GADGET5$ GADGET4$ GADGET3$ GADGET2$ GADGET1$
  343.      GADGET# 0
  344.      DO
  345.        I 1+ GADTEXT 12. D+ D!L         \ Set Text Strings
  346.      LOOP
  347.  
  348.  
  349.      GADGET# 0                         \ Set Gadget Links
  350.      DO
  351.        I 1+ GADGET# <
  352.        IF
  353.          I 2+ GADGET
  354.          I 1+ GADGET D!L
  355.        THEN
  356.      LOOP
  357.  
  358.      GADGET# 0                         \ Set IntuiText Pointers
  359.      DO
  360.        I 1+ GADTEXT
  361.        I 1+ GADGET 26. D+ D!L
  362.      LOOP
  363.  
  364.      GADGET# 0                         \ Set Border Pointers
  365.      DO
  366.        BORDER1 I 1+ GADGET 18. D+ D!L
  367.      LOOP
  368.  
  369.      COORD1 BORDER1 8. D+ D!L
  370.      ;
  371.  
  372.  \ ----------------------------------------------------------
  373.  \ Demo Window Auxiliaries
  374.  \ ----------------------------------------------------------
  375.  
  376.    $CONSTANT WINTITLE $GADGETDEMO$  \ Window Title for Demo window
  377.  
  378.    0. DVARIABLE WINDOW1             \ DVARIABLE to contain your Window handle
  379.  
  380.  \ ----------------------------------------------------------
  381.  \ Disable and enable single gadgets n1
  382.  \ ----------------------------------------------------------
  383.  
  384.    : ONGADGET             \ n1 - - -
  385.  
  386.      GADGET     0 AREG D!
  387.      WINDOW1 D@ 1 AREG D!
  388.      0.         2 AREG D!
  389.      INTUBASE -186  LIBRARY
  390.    ;
  391.  
  392.    : OFFGADGET            \ n1 - - -
  393.  
  394.      GADGET     0 AREG D!
  395.      WINDOW1 D@ 1 AREG D!
  396.      0.         2 AREG D!
  397.      INTUBASE -174  LIBRARY
  398.    ;
  399.  
  400.  \ ----------------------------------------------------------
  401.  \ Add and Remove single gadgets n1
  402.  \ ----------------------------------------------------------
  403.  
  404.    : ADDGADGET            \ n1 - - -
  405.  
  406.      GADGET     1 AREG D!
  407.      WINDOW1 D@ 0 AREG D!
  408.      -1.        0 DREG D!
  409.      INTUBASE -42  LIBRARY
  410.    ;
  411.  
  412.    : REMGADGET            \ n1 - - -
  413.  
  414.      GADGET     1 AREG D!
  415.      WINDOW1 D@ 0 AREG D!
  416.      INTUBASE -228  LIBRARY
  417.    ;
  418.  
  419.  \ ----------------------------------------------------------
  420.  \ Refresh n2 Gadgets after n1
  421.  \ ----------------------------------------------------------
  422.  
  423.    : REFRESHGADGETS      \ n1 n2 - - -
  424.  
  425.      0          0 DREG D!
  426.      GADGET     0 AREG D!
  427.      WINDOW1 D@ 1 AREG D!
  428.      0.         2 AREG D!
  429.      INTUBASE -432  LIBRARY
  430.    ;
  431.  
  432.  \ ----------------------------------------------------------
  433.  \ A set of dummy Gadget commands
  434.  \ ----------------------------------------------------------
  435.  
  436.    : G1 18 3 CURPUT ." GADGET1ACTION" ;
  437.    : G2 18 3 CURPUT ." GADGET2ACTION" ;
  438.    : G3 18 3 CURPUT ." GADGET3ACTION" ;
  439.    : G4 18 3 CURPUT ." GADGET4ACTION" ;
  440.    : G5 18 3 CURPUT ." GADGET5ACTION" ;
  441.    : G6 18 3 CURPUT ." GADGET6ACTION" ;
  442.  
  443.  \ ----------------------------------------------------------
  444.  \ The Gadgetnumber
  445.  \ ----------------------------------------------------------
  446.  
  447.  \ See the Helios Dictionary for full definition and description
  448.  \ of the Gadgetnumber.
  449.  \ Very briefly, the HeliOS Gadgetnumber is similar to a
  450.  \ menunumber and has the following format:
  451.  
  452.  \ Gadgetnumber in Binary Format: 0000000001011111
  453.  \ These bits are always set                 ^^^^^
  454.  \ and indicate that this is a Gadget, not a Menu Number.
  455.  
  456.  \ Gadgetnumber in Binary Format: 0000000001011111
  457.  \ Gadget number bits             ^^^^^^^^^^^      = Gadget 2
  458.  
  459.  \ You can replace the commands G1.......G6 defined above and used
  460.  \ in the Gadgetvector table below with any routines of your own.
  461.  
  462.  \ ----------------------------------------------------------
  463.  \ The Gadget Command Interpreter Vector Table
  464.  \ ----------------------------------------------------------
  465.  
  466.             BIN      0000000000111111 VARIABLE GADGETVECTORS  \ Gadget 1
  467.                   ' G1 CFA ,
  468.                      0000000001011111 ,             \ 2
  469.                   ' G2 CFA ,
  470.                      0000000001111111 ,             \ 3
  471.                   ' G3 CFA ,
  472.                      0000000010011111 ,             \ 4
  473.                   ' G4 CFA ,
  474.                      0000000010111111 ,             \ 5
  475.                   ' G5 CFA ,
  476.                      0000000011011111 ,             \ 6
  477.                   ' G6 CFA ,   DECIMAL
  478.                    HERE
  479.                    255 ,
  480.                   ' NOOP  CFA ,
  481.                   CONSTANT GADGEND
  482.  
  483.  \ --------------------------
  484.  \ Gadget Command Interpreter
  485.  \ --------------------------
  486.  
  487.    : GADGCHECK
  488.  
  489.      GADGEND
  490.      GADGETVECTORS
  491.      DO
  492.        I DDUP @
  493.        =
  494.         IF
  495.           2+ LEAP
  496.         THEN
  497.         DROP
  498.      4
  499.      +LOOP
  500.      GADGEND 2+
  501.      ;
  502.  
  503.      : GADGETACTION   DROP GADGETNUMBER GADGCHECK @EXECUTE ;
  504.  
  505.  \ ---------------------
  506.  \ Demonstration Program
  507.  \ ---------------------
  508.  
  509.    : TESTGADGETS
  510.  
  511.      TIMEOFF                          \ Switch off auto-time display
  512.  
  513.      INITGADGETS                      \ Initialise Gadget structures
  514.  
  515.      STDWINDOW                        \ Set up for standard Workbench window
  516.  
  517.      DRAGGAD                          \ Include Drag Gadget
  518.  
  519.      DEPTHGAD                         \ Include Depth Gadget
  520.  
  521.      CLOSEGAD                         \ Include Close gadget ..........
  522.  
  523.      WINDOWCLOSE 0!                   \ ..and set up Window Close Gadget Flag
  524.  
  525.      GADGLIST WINDOWSTRUCT 18 + D!    \ Install Gadget List in Window Struct
  526.  
  527.      WINTITLE                         \ Window Title Text String
  528.  
  529.      0 0 520 200                      \ Window Dimensions
  530.  
  531.      2 0                              \ 2-Bitplanes, no Superbitmap
  532.  
  533.      OPENWINDOW                       \ Now, at last, open the new Window
  534.  
  535.      DFLAG0= IF                       \ ??? Window failed to open ???
  536.                DDROP                  \ We have no window, so finish
  537.              ELSE
  538.                DTRIP                  \ Our window opened OK, so......
  539.                WINDOW1 D!             \ Store window handle
  540.                MAKEINWINDOW           \ Make Inputwindow
  541.                MAKEOUTWINDOW          \ Make Outputwindow
  542.                CUROFF                 \ Switch off cursor
  543.                1 GADGET#              \ From 1st gadget, all gadgets
  544.                REFRESHGADGETS         \ Display Gadgets
  545.                EVENTON                \ Switch on Event Reporting
  546.                WBENCHTOFRONT          \ Display Workbench
  547.  
  548.                CR CR ."    Hello!"    \ Hailing Text
  549.  
  550.                0 17 CURPUT            \ Set Text Start Position
  551.  
  552.                ."    Try all the Gadgets."               CR
  553.  
  554.                ."    Press <Esc> to exit this Demo,"     CR
  555.  
  556.                ."    or Click on the window CLOSE Gadget."
  557.  
  558.                BEGIN                  \ Input processing loop
  559.                  KEY
  560.                  DUP 1253 =  IF GADGETACTION THEN
  561.                  27 =                 \ Check for <Esc>
  562.                  WINDOWCLOSE @ OR     \ or Window Close Gadget
  563.                UNTIL                  \ Now Clean-up and Exit
  564.  
  565.                FORTHOUTWINDOW         \ Reset HeliOS Output
  566.                FORTHINWINDOW          \ Reset HeliOS Input
  567.                WINDOW1 D@ CLOSEWINDOW \ Close Window
  568.              THEN
  569.        TIMEON                         \ Switch on auto-time display
  570.        WBENCHTOBACK                   \ Move Workbench to back
  571.       ;
  572.  
  573.       TESTGADGETS
  574.  
  575.  \ ---------------------------------------------------------------------------
  576.  \ The End
  577.  \ ---------------------------------------------------------------------------
  578.